package cn.yusei.teamTribe.controller.school;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.yusei.teamTribe.constant.ResponseCode;
import cn.yusei.teamTribe.constant.RoleType;
import cn.yusei.teamTribe.exception.RoleNotFoundException;
import cn.yusei.teamTribe.service.school.SchoolRoleService;
import cn.yusei.teamTribe.util.ResponseUtil;

@Controller
public class SchoolRoleController {

	@Autowired
	private SchoolRoleService schoolRoleService;
	
	@RequestMapping(value="/schoolRole/get")
	public void get(@RequestParam int schoolId, @RequestParam int roleId, PrintWriter out)
	{
		if(schoolId <= 0 || !RoleType.isRoleType(roleId))
		{
			ResponseUtil.responseCode(out, ResponseCode.PARAM_ILLEGAL);
			return;
		}
		int id = 0;
		try
		{
			id = schoolRoleService.get(schoolId, roleId);
		}
		catch (RoleNotFoundException e)
		{
			e.printStackTrace();
			ResponseUtil.responseCode(out, ResponseCode.PARAM_ILLEGAL);
			return;
		}
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id", id);
		ResponseUtil.response(out, ResponseCode.REQUEST_SUCCESSED, param);
	}
	
}
